/*
 * @Author: Siogo
 * @Date: 2025-11-04 17:01:00
 * @LastEditors: Siogo 你的邮箱
 * @LastEditTime: 2025-11-05 11:15:14
 * @FilePath: /frontend/src/api/tb/terminalLog.ts
 * @Description: 终端日志管理API
 */
import { Page } from '../model/baseModel';
import { defHttp } from '/@/utils/http/axios';

/**
 * 终端日志类型枚举
 */
export enum TerminalLogType {
  ALERT_LOG = 'ALERT_LOG',
  PROCESS_LOG = 'PROCESS_LOG',
  RECEIVE_LOG = 'RECEIVE_LOG',
  RECEIVE_EXCEPTION_LOG = 'RECEIVE_EXCEPTION_LOG',
}

/**
 * 终端日志级别枚举
 */
export enum TerminalLogLevel {
  CRITICAL = 'CRITICAL',
  WARNING = 'WARNING',
  INFO = 'INFO',
}

/**
 * 实体ID接口
 */
export interface EntityId {
  id: string;
  entityType: string;
}

/**
 * 终端日志对象接口
 */
export interface TerminalLog {
  id: EntityId;
  createdTime: number;
  tenantId: EntityId;
  deviceId: EntityId;
  deviceName: string;
  logType: TerminalLogType;
  logLevel: TerminalLogLevel | string;
  contentSummary: string;
  contentDetails: string;
  occurTime: number;
  processStatus: string;
  processor?: string;
  slaStatus: string;
  slaDeadline?: number;
  duration: number;
  isCritical: boolean;
  criticalAlert: boolean;
  timeout: boolean;
}

/**
 * 终端日志查询参数接口
 */
export interface TerminalLogQueryParam {
  page: number;
  pageSize: number;
  deviceId?: string;
  logType?: TerminalLogType;
  logLevel?: TerminalLogLevel;
  startTime?: number;
  endTime?: number;
  textSearch?: string;
  sortProperty?: string;
  sortOrder?: string;
}

/**
 * 导出参数接口
 */
export interface TerminalLogExportParam {
  deviceId?: string;
  logType?: TerminalLogType;
  logLevel?: TerminalLogLevel;
  startTime?: number;
  endTime?: number;
  textSearch?: string;
  format: 'CSV' | 'EXCEL';
}

/**
 * 获取终端日志列表
 */
export function getTerminalLogList(params: TerminalLogQueryParam) {
  return defHttp.get<Page<TerminalLog>>({
    url: '/api/terminal/logs',
    params,
  });
}

/**
 * 根据ID获取终端日志详情
 */
export function getTerminalLogById(logId: string) {
  return defHttp.get<TerminalLog>({
    url: `/api/terminal/log/${logId}`,
  });
}

/**
 * 导出终端日志
 */
export function exportTerminalLogs(params: TerminalLogExportParam) {
  return defHttp.postJson<Blob>({
    url: '/api/terminal/logs/export',
    data: params,
    responseType: 'blob',
  });
}
